package conversions

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// 类型转换指令
// double转float
type D2F struct {
	base.NoOperandsInstruction
}

// double转int
type D2I struct {
	base.NoOperandsInstruction
}

// double转long
type D2L struct {
	base.NoOperandsInstruction
}

func (self *D2F) Execute(frame *runtime_area.Frame) {
	double := frame.OperandStack().PopDouble()
	frame.OperandStack().PushFloat(float32(double))
}

func (self *D2I) Execute(frame *runtime_area.Frame) {
	double := frame.OperandStack().PopDouble()
	frame.OperandStack().PushInt(int32(double))
}

func (self *D2L) Execute(frame *runtime_area.Frame) {
	double := frame.OperandStack().PopDouble()
	frame.OperandStack().PushLong(int64(double))
}